﻿namespace BM.Tools.WebControls.MForm.Navigation
{
    using System.Collections.Generic;

    /// <summary>
    /// StartingNavigator is a class, from which the search is started.
    /// </summary>
    /// <typeparam name="T">
    /// The type of the navigable object.
    /// </typeparam>
    public class StartingNavigator<T> : INavigator<T>
    {        
        private IEnumerable<T> startingNodes;

        /// <summary>
        /// Initializes a new instance of the <see cref="StartingNavigator{T}"/> class. 
        /// </summary>
        /// <param name="navigatorRoot">
        /// The navigatorRoot.
        /// </param>
        /// <param name="startingNodes">
        /// The starting nodes.
        /// </param>
        public StartingNavigator(INavigatorRoot<T> navigatorRoot, IEnumerable<T> startingNodes)
        {
            Root = navigatorRoot;
            this.startingNodes = startingNodes;
        }

        /// <summary>
        /// Gets Parent.
        /// </summary>
        /// <value>
        /// The parent.
        /// </value>
        public INavigator<T> Parent
        {
            get
            {
                return Root;
            }
        }

        /// <summary>
        /// Gets the navigator Root.
        /// </summary>
        /// <value>
        /// The navigator root object.
        /// </value>
        public INavigatorRoot<T> Root
        {
            get;
            private set;            
        }

        /// <summary>
        /// Provides the <see cref="NavigatorQuery{T}" /> object that can move through the tree.
        /// </summary>
        /// <param name="item">
        /// The item on which the query run.
        /// </param>
        /// <returns>
        /// the NavigatorQuery object
        /// </returns>
        public NavigatorQuery<T> Query(T item)
        {
            return Root.Query(item);
        }

        /// <summary>
        /// takes the nodes with which the search is started
        /// </summary>
        /// <returns>
        /// the initial enumerable of navigable nodes
        /// </returns>
        public IEnumerable<T> Select()
        {
            return startingNodes;
        }
    }
}